<?php
namespace app\vip_agent\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;


class Messages extends Base
{
    public function index()
    {
        $message = Db::name('message')
            ->alias('a')
            ->join('lc_messagetest b','a.messageID = b.id')
            ->where(['a.level'=>'1','a.rceID'=>session('user.id')])
            ->order('a.id','desc')
            ->paginate(15);
        $page = $message->render();
        return view('messages/index',['message'=>$message,'page'=>$page]);
    }


    public function details(){
        $message = Db::name('message')
            ->alias('a')
            ->join('lc_messagetest b','a.messageID = b.id')
            ->where(['a.level'=>'1','a.rceID'=>session('user.id'),'b.id'=>$_GET['id']])
            ->find();
        $up = Db::name('message')
            ->alias('a')
            ->join('lc_messagetest b','a.messageID = b.id')
            ->where(['a.level'=>'1','a.rceID'=>session('user.id'),'b.id'=>$_GET['id']])
            ->update(['Statue'=>1]);
        $count = Db::name('message')
            ->where(['level'=>'1','rceID'=>session('user.id'),'Statue'=>0])
            ->count();
        return view('messages/details',['message'=>$message,'count'=>$count]);
    }



}
